package main

import (
	"fmt"
	"reflect"
)

func reflectTest1() {
	myMap := make(map[string]string, 10)
	myMap["a"] = "a_value"
	myMap["b"] = "b_value"
	myMap["c"] = "c_value"
	t := reflect.TypeOf(myMap)
	fmt.Printf("myMap type is %v\n", t)

	v := reflect.ValueOf(myMap)
	fmt.Printf("value is %v\n", v)

	// struct
	myStruct := T{A: "a", B: "b"}
	v1 := reflect.ValueOf(myStruct)
	for i := 0; i < v1.NumField(); i++ {
		fmt.Printf("Field %d:%v\n", i, v1.Field(i))
	}

	for i := 0; i < v1.NumMethod(); i++ {
		fmt.Printf("method: %d:%v\n", i, v1.Method(i))
	}

	// 非完全理解 *****
	result := v1.Method(0).Call(nil)
	fmt.Println("result: ", result)
}

type T struct {
	A string
	B string
}

func (t T) String() string {
	return t.A + "1"
}

func main() {
	reflectTest1()
}
